package com.caiyi.financial.nirvana.sms.task;

import com.caiyi.financial.nirvana.sms.service.SmsUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 余额更新task
 */
public class UpdateBalanceTask implements Runnable {

    private static final Logger logger = LoggerFactory.getLogger(UpdateBalanceTask.class);
    private SmsUserService smsUserService;
    private String id;
    private Integer msgCount;

    public UpdateBalanceTask(SmsUserService smsUserService, String id, Integer msgCount) {
        this.smsUserService = smsUserService;
        this.id = id;
        this.msgCount = msgCount;
    }

    @Override
    public void run() {
        try {
            int count = smsUserService.updateById(id, msgCount);
            logger.info("UpdateBalanceTask update ! account = " + id + ", msgCount : " + msgCount);
            if (count == 0) {
                logger.error("UpdateBalanceTask error ! account = {}, msgCount : {}", id, msgCount);
            }
        } catch (Exception e) {
            logger.error("UpdateBalanceTask error !!! ", e);
        }
    }
}
